package dao.impl;

import java.sql.SQLException;
import java.util.Date;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import dao.AdminDao;
import model.Admin;
import model.User;
import util.JDBCUtiles;

public class AdminDaoImpl implements AdminDao {

	@Override
	public boolean register(String id, String name, String sex, String pwd1,String phone) throws SQLException {
		//得到QueryRunner对象
				QueryRunner qr = JDBCUtiles.getQueryRunner();
				//sql语句
				String sql = "INSERT INTO admin (AdminID,AdminName,AdminSex,AdminPwd,AdminTime,AdminPhone,AdminShow) VALUES (?,?,?,?,?,?,?)";
				Date date = new Date();
				int i = qr.update(sql,id,name,sex,pwd1,date,phone,"photos/1.jpg");
				return  i > 0 ? true : false;
	}

	@Override
	public Admin getAdminByIdAndPwd(String name, String pwd) throws SQLException {
		//得到QueryRunner对象
		QueryRunner qr = JDBCUtiles.getQueryRunner();
		//sql语句
		String sql = "SELECT * FROM admin WHERE AdminID=? AND AdminPwd=?" ;
		return qr.query(sql, new BeanHandler<Admin>(Admin.class),name,pwd);
	}

}
